package com.itheima.d1_reflect_field;


import org.junit.jupiter.api.Test;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

/**
 * 反射获取成员变量:
 *                  1.getField
 *                  2.getDeclareField
 *                  3.getFields
 *                  4.getDeclareFields
 */
public class demo1 {

    @Test
    public void getField() throws NoSuchFieldException {
        //1.获取类对象


    }

    @Test
    public void getDeclareField() throws NoSuchFieldException {
        //1.获取类对象
        Class c = Student.class;

        //2.获取单个成员变量
        Field f = c.getDeclaredField("name");
        f.setAccessible(true);
        System.out.println(f.getName()+"=====>"+f.getType());

    }


    @Test
    public void getFields() {
        //1.获取类对象
        Class c = Student.class;

        //2.获取全部public成员变量
        Field[] f = c.getFields();

        //3.遍历
        for (Field field : f) {
            System.out.println(field.getName()+"=======>"+field.getType());
        }

    }

    @Test
    public void getDeclareFields() {
        //1.获取类对象
        Class c = Student.class;

        //2.获取全部成员变量
        Field[] f = c.getDeclaredFields();

        //3.遍历
        for (Field field : f) {
            System.out.println(field.getName()+"=======>"+field.getType());
        }
    }

}
